<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>管理员管理页面</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">

<!-- Google Font -->
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet">

<!-- Template style -->
<link rel="stylesheet" href="dist/css/style.css">
<link rel="stylesheet" href="tables/et-line-font/et-line-font.css">
<link rel="stylesheet" href="tables/font-awesome/css/font-awesome.min.css">
<link type="text/css" rel="stylesheet" href="dist/weather/weather-icons.min.css">
<link type="text/css" rel="stylesheet" href="dist/weather/weather-icons-wind.min.css">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="sidebar-mini">
<div class="wrapper">

  <!-- 引入顶栏 -->
  <header class="main-header dark-bg">

    <!-- Logo -->
    <a href="index.html" class="logo dark-bg">
      <!-- mini logo for sidebar mini 50x50 pixels -->
      <span class="logo-mini"><img src="dist/img/logo.png" alt="Ovio"></span>
      <!-- logo for regular state and mobile devices -->
      <span class="logo-lg"><img src="dist/img/logo-lg.png" alt="Ovio"></span> </a>

    <!-- Header Navbar -->
    <nav class="navbar navbar-static-top" role="navigation">
      <!-- Sidebar toggle button-->
      <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button"> <span class="sr-only">Toggle navigation</span> </a>
      <div class="pull-left search-box">
        <forml class="search-form">
          <div class="input-group">
            <input type="text" name="search" class="form-control" placeholder="请输入管理员信息关键词" id="keyWord">
            <span class="input-group-btn">
            <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i> </button>
            </span></div>
        </forml>
        <!-- search form --> </div>
      <!-- Navbar Right Menu -->
      <div class="navbar-custom-menu">
        <ul class="nav navbar-nav">


          <!--邮箱登录-->
          <li class="dropdown notifications-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-envelope"></i>
            <div class="notify"> <span class="heartbit noticePoint"></span> <span class="point noticePoint"></span> </div>
          </a>
            <ul class="dropdown-menu">
              <li class="header" style="text-align: center"><span>请输入您的邮箱和授权码</span><br/>
                <span>--（目前仅支持QQ邮箱）--</span></li>
              <li>
                <input type="text" name="search" class="form-control" id="emailLogin" disabled="disabled" style="text-align: center;margin-top: 5%">
                <input type="text" name="search" class="form-control" id="password" placeholder="--请输入授权码--" style="text-align: center;margin-top: 5%">
              </li>
              <li class="footer" style="text-align: center;margin-top: 5%"><button type="button" class="btn btn-primary btn-outline btn-rounded" id="emailLoginButton">登录</button></li>
            </ul>
          </li>


          <!--收信箱-->
          <li class="dropdown messages-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-megaphone"></i>
            <div class="notify"> <span class="heartbit noticePoint"></span> <span class="point noticePoint"></span> </div>
          </a>
            <ul class="dropdown-menu">
              <li class="header" style="padding-bottom: 10%">
                <div>您有<span id="emailNum">0</span>条邮件未读</div>
              </li>
              <li>
                <ul class="menu" id="emailList">
                  <!--<li><a href="#">-->
                  <!--<div class="pull-left"><img src="dist/img/img1.jpg" class="img-circle" alt="User Image"></div>-->
                  <!--<h4>Florence Douglas</h4>-->
                  <!--<p>Lorem ipsum dolor sit amet.</p>-->
                  <!--<p><small><i class="fa fa-clock-o"></i> 2 mins</small></p>-->
                  <!--</a></li>-->
                  <!--<li><a href="#">-->
                  <!--<div class="pull-left"><img src="dist/img/img2.jpg" class="img-circle" alt="User Image"></div>-->
                  <!--<h4>Douglas Smith</h4>-->
                  <!--<p>Lorem ipsum dolor sit amet.</p>-->
                  <!--<p><small><i class="fa fa-clock-o"></i> 15 mins</small></p>-->
                  <!--</a></li>-->
                  <!--<li><a href="#">-->
                  <!--<div class="pull-left"><img src="dist/img/img3.jpg" class="img-circle" alt="User Image"></div>-->
                  <!--<h4>Lorence Deo</h4>-->
                  <!--<p>Lorem ipsum dolor sit amet.</p>-->
                  <!--<p><small><i class="fa fa-clock-o"></i> 35 mins</small></p>-->
                  <!--</a></li>-->
                  <!--<li><a href="#">-->
                  <!--<div class="pull-left"><img src="dist/img/img1.jpg" class="img-circle" alt="User Image"></div>-->
                  <!--<h4>Florence Douglas</h4>-->
                  <!--<p>Lorem ipsum dolor sit amet.</p>-->
                  <!--<p><small><i class="fa fa-clock-o"></i> 2 mins</small></p>-->
                  <!--</a></li>-->
                </ul>
              </li>
              <li class="footer" style="text-align: center;padding-top: 10%">
                <button disabled="disabled" id="writeEmail" type="button" id="writeEmail" class="btn btn-default btn-outline" style="margin-right: 10%">写邮件</button>
                <button disabled="disabled" id="enterEmail" type="button" class="btn btn-default btn-outline">进入邮箱</button>
              </li>
            </ul>
          </li>

          <!--右侧头像框-->
          <li class="dropdown user user-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <img src="dist/img/img1.jpg" class="user-image" alt="User Image"> <span class="hidden-xs"><span class="adminName">Florence Douglas</span></span> </a>
            <ul class="dropdown-menu">
              <li class="user-header">
                <div class="pull-left user-img"><img src="dist/img/img1.jpg" class="img-responsive" alt="User"></div>
                <p class="text-left"> <span class="adminName">Florence Douglas</span> <small id="email">florence@gmail.com</small> </p>
                <div class="view-link text-left"><a href="#">个人信息</a> </div>
              </li>
              <li><a href="#"><i class="icon-gears"></i> 账号设置</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="adminOut"><i class="fa fa-power-off"></i> <span id="adminOut">退出登录</span></a></li>
            </ul>
          </li>
        </ul>
      </div>
    </nav>
  </header>

  <!-- 侧边栏 -->
  <aside class="main-sidebar dark-bg">
    <section class="sidebar">
      <div class="user-panel black-bg">
        <div class="pull-left image"> <img src="dist/img/img1.jpg" class="img-circle" alt="User Image"> </div>
        <div class="pull-left info">
          <p class="adminName">Florence Douglas</p>
          <a href="#"><i class="fa fa-circle"></i> Online</a> </div>
      </div>
      <!-- Sidebar Menu -->
      <ul class="sidebar-menu" data-widget="tree">
        <li class="header dark-bg">Menu</li>
        <li class="treeview"><a href="#"><i class="fa fa-dashboard"></i> <span>数据详情</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a>
          <ul class="treeview-menu ">
            <li><a href="index.html"><i class="fa fa-angle-right"></i> 数据详情 1</a></li>
            <li><a href="getMoreTodayFund.html"><i class="fa fa-angle-right"></i> 数据详情 2</a></li>
            <li><a href="dashboard-3.html"><i class="fa fa-angle-right"></i> 数据详情 3</a></li>
          </ul>
        </li>
        <li class="treeview active"> <a href="#"><i class="fa fa-table"></i> <span>权限管理</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a>
          <ul class="treeview-menu">
            <li><a href="userManage.html"><i class="fa fa-angle-right"></i> 用户管理</a></li>
            <li class="active"><a href="adminManage.html"><i class="fa fa-angle-right"></i> 管理员管理</a></li>
            <li><a href="goodManage.html"><i class="fa fa-angle-right"></i> 商品管理</a></li>
          </ul>
        </li>
        <li class="treeview"> <a href="#"><i class="fa fa-bar-chart"></i> <span>业务管理</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a>
          <ul class="treeview-menu">
            <li><a href="charts/line.html"><i class="fa fa-angle-right"></i> 资质维护</a></li>
            <li><a href="charts/area.html"><i class="fa fa-angle-right"></i> 分类管理</a></li>
            <li><a href="charts/bar.html"><i class="fa fa-angle-right"></i> 流程管理</a></li>
            <li><a href="charts/pie.html"><i class="fa fa-angle-right"></i> 广告管理</a></li>
            <li><a href="charts/bubble.html"><i class="fa fa-angle-right"></i> 消息模板</a></li>
            <li><a href="charts/combinations.html"><i class="fa fa-angle-right"></i> 项目分类</a></li>
            <li><a href="charts/3d.html"><i class="fa fa-angle-right"></i> 项目标签</a></li>
          </ul>
        </li>
        <li class="treeview"> <a href="#"><i class="fa fa-files-o"></i> <span>业务审核</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a>
          <ul class="treeview-menu">
            <li><a href="pages/login.html"><i class="fa fa-angle-right"></i> 实名认证审核</a></li>
            <li><a href="register.html"><i class="fa fa-angle-right"></i> 广告审核</a></li>
            <li><a href="forgotPassword.html"><i class="fa fa-angle-right"></i> 众筹审核</a></li>
          </ul>
        </li>
      </ul>
      <!-- sidebar-menu -->
    </section>
  </aside>
  
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper"> 
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>管理员管理</h1>
      <ol class="breadcrumb">
        <li><a href="index.html"><i class="fa fa-home"></i> 首页</a></li>
        <li class="active"><i class="fa fa-envelope-o"></i> 权限管理</li>
        <li class="active"><i class="fa fa-bars"></i> 管理员管理</li>
      </ol>
    </section>
    
    <!-- Main content -->
    <section class="content container-fluid">
      <div class="row">
        <div class="col-md-12">
          <div class="chart-box">
            <h4 style="margin-top: 2%;margin-bottom: 2%;text-align: center">该页面数据来自Mysql，查询，请在上方蓝色框内输入；删改，请点击对应行；增加，请移步注册页面</h4>
            <div class="bs-example" data-example-id="hoverable-table">
              <table class="table table-hover">
                <thead>
                  <tr>
                    <td style="text-align:center;vertical-align:middle;font-size: 130%">序号</td>
					<td style="text-align:center;vertical-align:middle">
						<input style="zoom:150%" type="checkbox" value="check" name="checkBox" id="allChecked" />
					</td>
                    <td style="text-align:center;vertical-align:middle;font-size: 130%">账号</td>
                    <td style="text-align:center;vertical-align:middle;font-size: 130%">姓名</td>
                    <td style="text-align:center;vertical-align:middle;font-size: 130%">邮箱</td>
					<td align="center"><span style="margin-right: 15%;font-size: 130%">操作</span><button type="button" class="btn btn-danger btn-rounded" id="deleteAdminByList">批量删除</button></td>
                  </tr>
                </thead>
                <tbody>
                  <!--<tr>-->
                    <!--<td scope="row" style="text-align:center;vertical-align:middle;">1</td>-->
					<!--<td style="text-align:center;vertical-align:middle;">-->
						<!--<input type="checkbox" value="check" name="checkBox"/>-->
					<!--</td>-->
                    <!--<td style="text-align:center;vertical-align:middle;">Mark</td>-->
                    <!--<td style="text-align:center;vertical-align:middle;">Otto</td>-->
                    <!--<td style="text-align:center;vertical-align:middle;">@mdo</td>-->
					<!--<td style="text-align:center;vertical-align:middle;">-->
						<!--<button type="button" class="btn btn-primary btn-outline btn-rounded"><i class=" glyphicon glyphicon-check"></i></button>-->
						<!--<button type="button" class="btn btn-success btn-outline btn-rounded"><i class=" glyphicon glyphicon-pencil"></i></button>-->
						<!--<button type="button" class="btn btn-danger btn-outline btn-rounded"><i class=" glyphicon glyphicon-remove"></i></button>-->
					<!--</td>-->
                  <!--</tr>-->
                </tbody>
                <tfoot>
                  <tr>
                    <td align="center" colspan="6">
                      <ul class="pagination pagination-lg" align="center">
                        <!--<li><a aria-label="Previous"> <span aria-hidden="true">&laquo;</span> </a> </li>-->
                        <!--<li><a id="pageOne">1</a></li>-->
                        <!--<li><a id="pageTwo">2</a></li>-->
                        <!--<li><a id="pageThree">3</a></li>-->
                        <!--<li><a id="pageFour">4</a></li>-->
                        <!--<li><a id="pageFive">5</a></li>-->
                        <!--<li> <a aria-label="Next"> <span aria-hidden="true">&raquo;</span> </a> </li>-->
                      </ul>
                    </td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </div> 
      </div>
    </section>
    <!-- content --> 
  </div>
  <!-- content-wrapper --> 
  
  <!-- Main Footer -->
  <footer class="main-footer dark-bg">
    <div class="pull-right hidden-xs"> Version 1.0</div>
    Copyright &copy; 2017 Yourdomian. All rights reserved. </footer>
</div>
<!-- wrapper --> 

<!-- jQuery --> 
<script src="dist/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="dist/js/ovio.js"></script>
<script src="dist/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="adminCommon.js"></script>
<script type="text/javascript">
  $(function () {

    // adminList请求,展示页面
    // 后一页按钮要用到，所以提出来
    var pages=0;
    function adminList(keyWord,currentPage){
      $.post("adminList", {"keyWord": keyWord, "currentPage": currentPage}, function (pageInf) {
          // list长度，最大不超过20，即每页最大条数
          var length = pageInf.list.length;
          var tbodyHtml="";
          for (var i=0;i<length;i++) {
              tbodyHtml+="<tr>\n" +
                  "                    <td scope=\"row\" style=\"text-align:center;vertical-align:middle;font-size: 130%\">"+(i+1)+"</td>\n" +
                  "\t\t\t\t\t<td style=\"text-align:center;vertical-align:middle;\">\n" +
                  "\t\t\t\t\t\t<input style=\"zoom:150%\" type=\"checkbox\" primaryKey=\""+pageInf.list[i].id+"\" value=\"check\" name=\"checkBox\" class=\"checkUnit\" />\n" +
                  "\t\t\t\t\t</td>\n" +
                  "                    <td style=\"text-align:center;vertical-align:middle;font-size: 130%\">"+pageInf.list[i].adminaccount+"</td>\n" +
                  "                    <td style=\"text-align:center;vertical-align:middle;font-size: 130%\">"+pageInf.list[i].adminname+"</td>\n" +
                  "                    <td style=\"text-align:center;vertical-align:middle;font-size: 130%\">"+pageInf.list[i].email+"</td>\n" +
                  "\t\t\t\t\t<td style=\"text-align:center;vertical-align:middle;\">\n" +
                  "\t\t\t\t\t\t<button type=\"button\" class=\"btn btn-primary btn-outline btn-rounded\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"查看详情\"><i style=\"font-size: 130%\" class=\" glyphicon glyphicon-check\"></i></button>\n" +
                  "\t\t\t\t\t\t<button type=\"button\" onclick=\"updateOneAdmin(this)\" class=\"btn btn-success btn-outline btn-rounded\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"信息修改\"><i style=\"font-size: 130%\" class=\" glyphicon glyphicon-pencil\"></i></button>\n" +
                  "\t\t\t\t\t\t<button type=\"button\" onclick=\"deleteOneAdmin(this)\" class=\"btn btn-danger btn-outline btn-rounded\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"删除管理员\"><i style=\"font-size: 130%\" class=\" glyphicon glyphicon-remove\"></i></button>\n" +
                  "\t\t\t\t\t</td>\n" +
                  "                  </tr>";
          }
          $("tbody").html(tbodyHtml);
          //一共的页码数
          pages = pageInf.pages;
          var pageButton="";
          // 设置前一页按钮
          pageButton += "<li><a aria-label=\'Previous\' id=\'Previous\'> <span aria-hidden=\'true\'>&laquo;</span> </a> </li>\n";
          // 强制规定5个分页，数据小于5页，都以第一页为开头
          if (pages<=5){
              for (var i =0;i<pages;i++){
                  pageButton+="<li><a id=\'page"+(i+1)+"\'>"+(i+1)+"</a></li>\n"
              }
          }else {
              // 头5页的显示
              if (currentPage-2<=1){
                  for (var i =0;i<5;i++){
                      pageButton+="<li><a id=\'page"+(i+1)+"\'>"+(i+1)+"</a></li>\n"
                  }
              }else if(Number(currentPage)+2>=pages){
                  //后5页的显示
                  var firstPage1=pages-4;
                  for (var i =0;i<5;i++){
                      pageButton+="<li><a id=\'page"+(i+1)+"\'>"+(firstPage1+i)+"</a></li>\n"
                  }
              }else{
                  var firstPage2=currentPage-2;
                  for (var i =0;i<5;i++){
                      pageButton+="<li><a id=\'page"+(i+1)+"\'>"+(firstPage2+i)+"</a></li>\n"
                  }
              }
          }
          //设置后一页按钮
          pageButton += "<li> <a aria-label=\'Next\' id=\'Next\'> <span aria-hidden=\'true\'>&raquo;</span> </a> </li>\n";
          $(".pagination-lg").html(pageButton);

          // (function($) {})(jQuery);这种js代码就应该放在最后加载，才会生效
          setTimeout("delayLoadScript();" ,500);
      });
    }


    // 初始的时候
    var currentPage = 1;
    var keyWord = "";


    // 搜索按钮一点击就开始post请求
    $("#search-btn").click(function () {
        // 获取到当前页面，仅在点击时获取
        currentPage = 1;
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });

    // 点击分页符时候，获取到当前页，进行post请求,js新生成的标签不能用click()进行触发
    $(".pagination-lg").on("click","#page1",function () {
        currentPage=$("#page1").text();
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });
    $(".pagination-lg").on("click","#page2",function () {
        currentPage=$("#page2").text();
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });
    $(".pagination-lg").on("click","#page3",function () {
        currentPage=$("#page3").text();
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });
    $(".pagination-lg").on("click","#page4",function () {
        currentPage=$("#page4").text();
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });
    $(".pagination-lg").on("click","#page5",function () {
        currentPage=$("#page5").text();
        keyWord = $("#keyWord").val();
        adminList(keyWord,currentPage);
    });
    $(".pagination-lg").on("click","#Previous",function () {
      keyWord = $("#keyWord").val();
      if (currentPage==1){
          adminList(keyWord,currentPage);
      }else{
          currentPage--;
          adminList(keyWord,currentPage);
      }
    });
    $(".pagination-lg").on("click","#Next",function () {
      keyWord = $("#keyWord").val();
      if (currentPage==pages){
          adminList(keyWord,currentPage);
      }else{
          currentPage++;
          adminList(keyWord,currentPage);
      }
    });

    //点击侧边栏的话，就用上面定义的初始值
    //   post请求
    adminList(keyWord,currentPage);


    // 全选框的操作
    $("#allChecked").click(function () {
        if($("#allChecked").is(":checked")){
            // 必须用prop(),不能用attr(),不然全选只会生效一次
            $(".checkUnit").prop("checked", true);
        }else {
            $(".checkUnit").prop("checked",false);
        }
    });
    // 获取复选框单元的对应数据主键，存进一个数组里面

    $("#deleteAdminByList").click(function () {
        var pkArray=new Array();
       $(".checkUnit").each(function () {
           if($(this).prop("checked")==true){
               var primaryKey = $(this).attr("primaryKey");
               pkArray.push(primaryKey);
           }
       });
       // 数组转字符串，作为json数据
       var pkArrayJson = pkArray.toString();
       if(pkArrayJson!="" && pkArrayJson!=null){
          layer.confirm("您确定要删除勾选的项目？", {
              btn: ["是","否"] //按钮
          }, function(){
            $.post("deleteAdminByList",{"pkArray":pkArrayJson},function (resultEntity) {
                if (resultEntity.resultFlag==true){
                    layer.msg("批量删除成功");
                    // 批量删除后直接重定向会当前页面，目的是清空pkArray
                    setTimeout("window.location.replace(\"adminManage.html\");",700);
                } else {
                    layer.msg("批量删除失败");
                }
            });
          }, function(){});
       }
    });


  });

  // 加载弹出框的js代码
  function delayLoadScript() {
      var script = document.createElement('script');
      script.src = "dist/js/tooltips.js";
      document.body.appendChild(script);
  }


  // 单项删除按钮，onclick事件的对应方法，定义在外面
  function deleteOneAdmin(obj) {
      layer.confirm("您确定要删除当前项目？", {
          btn: ["是","否"] //按钮
      }, function(){
          //获取直接父元素
          var parent = $(obj).parent("td");
          // 获取上四个节点兄弟元素的子元素input
          var children = parent.prev().prev().prev().prev().children("input");
          // 获取input的primaryKey属性值
          var primaryKey = children.attr("primaryKey");
          $.post("deleteOneAdmin",{"primaryKey":primaryKey},function (resultEntity) {
              if (resultEntity.resultFlag==true){
                  layer.msg("删除成功");
                  setTimeout("window.location.replace(\"adminManage.html\")",500);
              } else {
                  layer.msg("删除失败");
              }
          });
      }, function(){});
  }

  function updateOneAdmin(obj) {
      layer.confirm("您确定要修改当前项目？", {
          btn: ["是","否"] //按钮
      }, function() {
          //获取直接父元素
          var parent = $(obj).parent("td");
          // 获取上四个节点兄弟元素的子元素input
          var children = parent.prev().prev().prev().prev().children("input");
          // 获取input的primaryKey属性值
          var primaryKey = children.attr("primaryKey");
          // 拼接url参数，重定向
          window.location.replace("adminUpdate.html?primaryKey=" + primaryKey);
      },function () {});
  }


</script>
</body>
</html>